<template>
  <div style="height:100%;width:100%">
    <el-row class="mainContent" >
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="filters" size="small" style="text-align:left;" :rules="filte" ref="filters">
          <el-form-item prop="id">
            <el-input v-model="filters.serialnumber" placeholder="流水编号" clearable></el-input>
          </el-form-item>
          <el-form-item prop="id">
            <el-input v-model="filters.username" placeholder="用户名" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="filters.orgin" placeholder="充值方式" clearable>
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="filters.state" placeholder="状态" clearable>
              <el-option
                v-for="item in optionss"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="block">
              <el-date-picker
                v-model="filters.begtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <div class="block">
              <el-date-picker
                v-model="filters.endtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  @click="getUsers">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <!--列表-->
      <el-table :data="users" highlight-current-row  v-loading="listLoading" style="width: 100%;">
        <el-table-column prop="serialnumber" label="流水编号" >
        </el-table-column>
        <el-table-column prop="username" label="用户名" >
        </el-table-column>
        <el-table-column  label="手机号" prop="mobile" >
        </el-table-column>
        <el-table-column  label="金额" prop="amount" >
        </el-table-column>
        <el-table-column  label="充值方式"  >
          <template slot-scope="scope">
            <span>{{scope.row.orgin | orginFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column  label="操作员" prop="adminUsercode" >
        </el-table-column>
        <el-table-column  label="状态"  >
          <template slot-scope="scope">
            {{scope.row.state | stateFormat}}
          </template>
        </el-table-column>
        <el-table-column  label="充值时间" prop="time" >
        </el-table-column>
        <el-table-column  label="操作" v-if="$store.state.routes.routes.yhczshOperate">
          <template slot-scope="scope">
            <el-button
              size="mini" type="text"
              @click="checkDialog(scope.$index, scope.row)" v-if="scope.row.state==10">审核</el-button>
            <span v-else>-</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10"  :total="total" style="float:right;">
      </el-pagination>

      <el-dialog title="审核" :visible.sync="checkDialogVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
        <el-form :model="checkForm" :rules="rules" ref="editPwdForm" status-icon label-width="100px" style="text-align:left">
          <el-form-item label="id" style="display: none">
            <el-col :span="22">
              <el-input v-model="checkForm.id"  disabled></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="用户名">
            <el-col :span="22">
              <el-input v-model="checkForm.username"  disabled></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="手机号">
            <el-col :span="22">
              <el-input type="text"  v-model="checkForm.mobile" disabled></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="充值时间">
            <el-col :span="22">
              <el-input type="text"  v-model="checkForm.time" disabled></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="金额" >
            <el-col :span="22">
              <el-input type="text"  v-model="checkForm.amount" disabled></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="财务密码" prop="financePwd">
            <el-col :span="22">
              <el-input type="password"  v-model="checkForm.financePwd" ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="凭证图片">
            <input type="file" @change="onFileChange">
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click.native="submitCheckDialog(-1)" type="danger">拒 绝</el-button>
          <el-button type="primary" @click.native="submitCheckDialog(1)" :loading="editPwdLoading">通 过</el-button>
        </div>
      </el-dialog>
    </el-row>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        options: [{
          value: '5',
          label: '连连支付'
        }, {
          value: '10',
          label: '线下转账'
        }],
        optionss: [{
          value: '10',
          label: '提交'
        },{
          value: '11',
          label: '成功'
        }, {
          value: '12',
          label: '失败'
        }],
        filters: {
          begtime:'',
          endtime:'',
          serialnumber:'',
          orgin:'',
          state:'',
          username:''
        },
        editForm:{},
        editFormRules:{},
        checkForm:{},
        users:[],
        page: 1,
        total: 0,
        listLoading: false,
        filte:{},
        dialogFormVisible:false,
        editPwdLoading:false,
        checkDialogVisible:false,
        imgBase64: '',
        rules: {
          financePwd: [{ required: true, message: "请输入财务密码", trigger: "blur" }],
        }
      };
    },
    filters:{
      stateFormat(val){
        switch (val){
          case 10:
            return '提交';
            break
          case 11:
            return '成功';
            break
          case 12:
            return '失败';
            break
        }
      },
      orginFormat(val){
        switch (val){
          case 5:
            return '连连支付';
            break
          case 10:
            return '线下转账';
            break
        }
      }
    },
    created() {
      this.getUsers();
    },
    methods: {
      getUsers() {
        this.users = []
        this.listLoading = true;
        var obj = {
          data:{
            username:this.filters.username,
            serialnumber:this.filters.serialnumber,
            state:this.filters.state,
            orgin:this.filters.orgin,
            begtime:this.filters.begtime==''||this.filters.begtime==0||this.filters.begtime==null?'':Math.round(new Date(this.filters.begtime).getTime()/1000),
            endtime:this.filters.endtime==''||this.filters.endtime==0||this.filters.endtime==null?'':Math.round(new Date(this.filters.endtime).getTime()/1000),
            pageNo:this.page
          }
        };
        this.$http('sys/recharge/list.do',obj).then(resp => {
          if(resp.code==1){
            this.users = resp.data.list;
            this.total = resp.data.total;
          }
          this.listLoading = false;
        });

      },
      handleCurrentChange(val) {
        this.page = val;
        this.getUsers();
      },
      checkDialog(index,row){
        if(!this.$store.state.routes.routes.yhczshOperate){
          this.$message({
            message:'无权限',
            type:'error'
          })
          return
        }
        this.checkForm = row
        this.imgBase64=''
        this.checkDialogVisible = true
      },
      submitCheckDialog(state){
          this.$refs["editPwdForm"].validate(valid => {
              if (valid) {
                  this.$confirm('确认执行此操作么', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                  }).then(() => {
                    this.$http('sys/recharge/audit.do',{data:{rechrageId:this.checkForm.id,state:state,img:this.imgBase64,financePwd:this.checkForm.financePwd}}).then(resp => {
                      if(resp.code==11){
                        this.$message({
                          message:resp.msg,
                          type:'success'
                        })
                      }else{
                        this.$message({
                          message:resp.msg,
                          type:'error'
                        })
                      }
                      this.checkDialogVisible = false;
                      this.getUsers()
                    });
                  }).catch(() => {

                  });
            } else {
                  return false;
                }
        });
      },
      onFileChange(e) {
        var files = e.target.files || e.dataTransfer.files;
        if (!files.length)
          return;
        this.createImage(files[0]);
      },
      createImage(file) {
        var image = new Image();
        var reader = new FileReader();
        var vm = this;

        reader.onload = (e) => {
          vm.image = e.target.result;
          this.imgBase64 = vm.image
        };
        reader.readAsDataURL(file);

      },
    }
  };
</script>

<style scoped>


  .el-table:hover{
    cursor: pointer !important;
  }
</style>
